import os,re,pickle
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
import abc

readpath = r'G:\software\work\finalhomework\video'

labels={'美国队长3': 7.9, '你的名字': 8.4, '我和我的祖国': 7.9, '攀登者': 6.2, '火星救援': 8.4,'美国队长2': 8, '钢铁侠': 8.3,'海蒂和爷爷':9.2,
'决战中途岛': 7.7, '天气之子': 7.1, '秒速五厘米': 8.3, '小丑': 8.8, '老少威尔·史密斯同屏对决': 7.1, '冰雪奇缘2': 7.3,'克里斯托弗':8,'企鹅高速公路':7.8,
'降魔传':2.9,'风雨咒':6.9,'大闹天竺':3.7,'王牌逗王牌':3.3,'情遇曼哈顿':3.9,'全球风暴':6,'反贪风暴':5.9,'封神传奇':2.9,'港囧':5.7,'恶棍天使':4.1,
'父子雄兵':4.7,'胖子行动队':4.2,'上海王':4.8,'奇门遁甲':4.4,'中国合伙人2':4.1,'麻烦家族':4.5,'超级快递':4.5,'黄金兄弟':5,'狂兽':5,'神秘家族':4.9,
'龙虾刑警':4.9,'空天猎':5,'祖宗十九代':4.2,'西游记女儿国':4.4,'百团大战':5,'情圣':6,'心理罪':5.9,'来电狂响':5.8,'少年班':5.9,'有完没完':5.4,
'蝙蝠侠《黑暗骑士》':9.2,'星际穿越':9.3,'泰坦尼克号':9.4,'少年派的奇幻漂流':9,'何以为家':9.1,'盗梦空间':9.3,'飞屋环游记':9,
'机器人总动员':9.3,'驴得水':8.3,'湄公河行动':8,'无名之辈':8.1,'天才枪手':8.2,'哪吒':8.5,'十二公民':8.4,'头号玩家':8.7,
'无问西东':7.6,'神秘巨星':7.7,'杀破狼':7.1,'闪光少女':7.3,'白蛇 缘起':7.9,'火锅英雄':7.2,'七月与安生':7.6,'暴雪将至':7,'找到你':7.4,'一个勺子':7.7,
'超时空同居':6.9,'南极之恋':6.7,'疯狂的外星人':6.4,'英伦对决':7,'张子枫彭昱畅':6.9,'健忘村':6.7,'心花路放':7.1,'寒战':7,
'暴裂无声':8.3,'西游记之大圣归来':8.3,'师父':8.1,'喊·山':8.4,'萨利机长':8.3,'罗小黑战记':8.2,'幸运是我':8,'寄生虫':8.7,'狗十三':8.2,
'王牌特工 2':6.9,'生存家族':8.1,'解忧杂货铺':5,'侠盗联盟':5.2,'睡在我上铺的兄弟':5.3,'鼠胆英雄':5.4,'道士下山':5.4,'冰河追凶':5.7,'煎饼侠':5.8
,'狄仁杰之四大天王':6.1,'破·局':6.2,'大人物':6.5,'拆弹专家':6.3,'北京遇上西雅图之不二情书':6.4}

def judge():
    movies=[]
    for root, dirs, files in os.walk(readpath):
        for file in files:
            movies.append(file)
    #print(movies)
    marks=[]

    flag=0
    for item in movies:
        flag=0
        for l in labels:
            m=re.search(l,item)
            if m is not None:
                marks.append(labels[l])
                flag=1
        if flag==0:
            print(item)

    assert len(marks)==len(movies),   '录入的电影预告片是否和录入的评分数不相等'
    assert len(labels)==len(movies),  '录入的电影预告片是否和录入的评分数不相等'
    assert len(labels)>=100,  '电影预告片数目不够100'

    print(len(marks),len(movies),len(labels))
    #print(marks)

    for l in labels:
        flag=0
        for item in movies:
            m=re.search(l,item)
            if m is not None:
                flag=1
        if flag==0:
            print(l)

    label = []
    for item in labels:
        label.append(labels[item])
    return label

class data(metaclass=abc.ABCMeta):
    def __init__(self):
        pass
    @abc.abstractmethod
    def write2file(self):
        pass
    @abc.abstractmethod
    def show(self):
        pass
    @abc.abstractmethod
    def describe(self):
        pass

class data_label(data):   #继承自数据处理的抽象类
    '''
    电影评分类
    '''
    def __init__(self,label):
        self.label=pd.Series(label,name='remarks of movie trailers')

    def write2file(self):
        with open(r'G:\software\work\finalhomework\video_detection\label.pkl','wb') as f:
            pickle.dump(self.label, f)

    def show(self):
        plt.figure()
        '''self.label.plot(kind='bar')'''
        sns.distplot(self.label,bins=40)
        plt.show()

    def describe(self):
        data=self.label
        print(data)
        print(data.describe())

if __name__=='__main__':
    label=judge()
    print(label)
    with open(r'G:\software\work\finalhomework\video_detection\label.pkl','wb') as f:
        pickle.dump(label, f)
    l=data_label(labels)
    l.describe()
    l.show()
    #l.write2file()